<template>
  <el-container :style="{
    left: collapse? '0px':'200px'}">
    <!-- 侧边栏 -->
    <el-aside :width="collapse? '0px':'200px'">
      <div class="aside-nav">
        <div class="user-info">
          <img src="../../assets/timg.jpg"
               alt="">
        </div>
        <section class="list-ul">
          <router-link class="el-icon-location-outline item"
                       to="/Home"
                       @click.native="collapse=true">首页</router-link>
          <router-link class="el-icon-mobile-phone item"
                       to="/personal"
                       @click.native="collapse=true">个人中心</router-link>
          <a class="el-icon-info item line"
             @click="logout()">退出</a>
        </section>
      </div>
    </el-aside>
    <el-container>
      <!-- 头部header -->
      <el-header>
        <div class="nav-left"
             @click="collapse = !collapse">
          <i class="iconfont icon-caidan"></i>
        </div>
        <span>文库吧</span>
      </el-header>
      <!-- 中间主体 -->
      <el-main @click.native="collapse = true">
        <router-view></router-view>
      </el-main>
    </el-container>
  </el-container>
</template>
<script>
export default {
  data () {
    return {
      collapse: true
    }
  },
  methods: {
    logout () {
      this.$cookie.delete('token')
      this.$router.push('/')
    }
  }
}
</script>

<style lang="less">
.el-container {
  position: relative;
  width: 100%;
  height: 100%;

  // 头部
  .el-header {
    background: #ffffff;
    box-shadow: 0 2px 8px 0 rgba(0, 0, 0, 0.2);
    color: #333;
    text-align: center;
    height: 44px !important;
    line-height: 44px;
    .nav-left {
      width: 40px;
      float: left;
      color: #16c79d;
      margin-left: -15px;
    }
    span {
      font-size: 18px;
      color: #16c79d;
      letter-spacing: 1.12px;
    }
  }

  // 侧边栏
  .el-aside {
    position: absolute;
    top: 0px;
    bottom: 0px;
    left: -200px;
    width: 200px;
    z-index: 1000;
    background: rgba(0, 0, 0, 0.4);
    color: #333;
    text-align: center;
    height: 100%;
    // line-height: 200px;
    .aside-nav {
      margin-top: 50px;
      text-align: center;
      .user-info {
        width: 40px;
        height: 40px;
        border: 1px solid #16c79d;
        border-radius: 50%;
        margin: 10px auto;
        img {
          width: 100%;
          height: 100%;
          border-radius: 50%;
        }
      }
    }
    .list-ul {
      margin: 0 24px;
      border-top: 1px solid #d4d4d4;
      overflow: hidden;
      padding-top: 9%;
      .el-icon-location-outline:before {
        margin-right: 30px;
      }
      .line {
        border-top: 1px solid white;
      }
      .el-icon-mobile-phone::before {
        margin-right: 30px;
      }
      .el-icon-info::before {
        margin-right: 30px;
      }
      .item {
        display: block;
        font-size: 14px;
        font-weight: 200;
        padding: 9% 0;
        text-align: left;
        text-indent: 1px;
        line-height: 15px;
        color: white;
        font-weight: 700;
        letter-spacing: 1px;
      }
    }
  }

  // 主体内容
  .el-main {
    color: #333;
    text-align: center;
    padding: 10px;
  }
}
</style>
